import javax.swing.table.*;





/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MasterList.java
 *
 * Created on Jul 20, 2010, 9:52:31 PM
 */

/**
 *
 * @author adam
 */
public class MasterList extends javax.swing.JFrame {

    //sets up table to be used in project
        Object[][] TableData = Database.getEntireTable();
        String[] TableColoumnNames=Database.Columns;
        TableModel model = new DefaultTableModel(TableData, TableColoumnNames);


    public MasterList(){


                       initComponents();

    }

    public static void invokeNewMasterList() {

        //sets up a new instance of the master list when invoked
           java.awt.EventQueue.invokeLater(new Runnable() {
          @Override
            public void run() {
               new MasterList().setVisible(true);

            }


        });

    }


    

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jToolBar1 = new javax.swing.JToolBar();
        jButton2 = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("OBD2ner Master List");
        setAlwaysOnTop(true);

        jTable1.setModel(model);
        jTable1.setColumnSelectionAllowed(true);
        jTable1.setFillsViewportHeight(true);
        jScrollPane1.setViewportView(jTable1);

        jToolBar1.setRollover(true);
        jToolBar1.setName("Master List Controls"); // NOI18N

        jButton2.setText("set values");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton2);

        jButton1.setText("refresh");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 806, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 782, Short.MAX_VALUE)
                .addGap(12, 12, 12))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 346, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

       //updates the master list with all data from Status.Table
        Object Table[][] = Database.getEntireTable();
        int rows = Table.length;
        int col = Table[1].length;
        int CurrentRow=0;
        int CurrentCol=0;
        Log.level2("Updating UI Columns: " + col + " Rows: " + rows );
            while (CurrentRow < rows ){
                while (CurrentCol < col ){
                    this.jTable1.setValueAt(Table[CurrentRow][CurrentCol], CurrentRow,CurrentCol);
                    ++CurrentCol;
               
                    
                }
                CurrentCol=0;
                ++CurrentRow;
            }



    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed

        //updates Status.Table with all values from Master List
        Object Table[][] = Database.getEntireTable();
        int rows = Table.length;
        int col = Table[1].length;
        int CurrentRow=0;
        int CurrentCol=0;
        Log.level2 ("Setting Main Columns: " + col + " Rows: " + rows );
            while (CurrentRow < rows ){
                while (CurrentCol < col ){
                    Table[CurrentRow][CurrentCol] = (String) this.jTable1.getValueAt(CurrentRow,CurrentCol);
                    ++CurrentCol;


                }
                CurrentCol=0;
                ++CurrentRow;
            }

    }//GEN-LAST:event_jButton2ActionPerformed

    /**
    * @param args the command line arguments
    */
 

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JToolBar jToolBar1;
    // End of variables declaration//GEN-END:variables

}
